﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Agency_ShowUpdate : System.Web.UI.Page
{
    string _ID = "";
    protected void Page_Load(object sender, EventArgs e)
    {
         System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            string _strSql;
            if (Request.QueryString["ID"] != null)
            {
                _ID = SysFun.IsSQL(Request.QueryString["ID"].ToString());
            }
            if (!IsPostBack)
            {
                if (_ID != "")
                {
                    Db db = new Db();
                    System.Data.IDataReader dr;
                    _strSql = "select * from show where id=" + _ID;
                    dr = db.DataReader(_strSql);
                    while (dr.Read())
                    {
                        txtShowName.Text = SysFun.ToTrim(dr["ShowName"]);
                        rdoShowSort.SelectedValue = SysFun.ToTrim(dr["ShowSort"]);
                        txtProjectId.Text = SysFun.ToTrim(dr["ShowProject"]);
                        txtShowDate.Text = SysFun.ToTrim(dr["ShowDate"]);
                        txtProjectId.Visible = false;
                        txtShowDate.Visible = false;
                    }
                    dr.Close();
                    dr.Dispose();
                    db.Close();

                }
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string _ProjectId = "", _ShowSort, _strSql,_ShowUrl="";
        _ProjectId = txtProjectId.Text.ToString();
        if (_ProjectId != "")
        {
            _ShowSort = rdoShowSort.SelectedValue;
            int _rowCun = 0;
            Db db1 = new Db();
            System.Data.IDataReader dr;
            _strSql = "select count(ID) as cun from dbo.show where   ShowProject=" + _ProjectId + " and ShowSort='" + _ShowSort + "' and ID<>" + _ID;
            dr = db1.DataReader(_strSql);
            if (dr.Read())
            {
                _rowCun = SysFun.ToInt(dr["cun"]);
            }
            dr.Close();
            dr.Dispose();

            if (_rowCun > 0)
            {
                Response.Write("<script language=JavaScript>alert('已经存在该项目的公示信息，不能重复添加！！！');</script>");
            }
            else
            {
                if (_ShowSort == "1")
                {
                    _ShowUrl = "PrintWholeKBRecord.aspx";
                }
                else if (_ShowSort == "2")
                {
                    _ShowUrl = "PrintWholeZBRecord.aspx";
                }
                else if (_ShowSort == "3")
                {
                    _ShowUrl = "PrintWholeJJRecord.aspx";
                }
                _strSql = "update Show set ShowName='" + txtShowName.Text.ToString() + "', ShowProject='" + _ProjectId + "',ShowSort='" + _ShowSort + "', ShowUrl='" + _ShowUrl + "', ShowDate='" + txtShowDate.Text + "'  where ID=" + _ID;
                db1.Command(_strSql);
                 HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                 HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "Show", _strSql, "../Agency/ShowUpdate.aspx");

                Response.Write("<script>alert('保存成功！！！');</script>");
            }
            db1.Close();
            Response.Write("<script>window.opener.location.reload();window.close();</script>");
        }
    }
}
